Cell density
p_counts <- ggplot(counts, aes(x = ExactTime, y = Total.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom")+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
labs(title="Total population")+
guides(color = FALSE)
p_HNA <- ggplot(counts, aes(x = ExactTime, y = HNA.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom")+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
labs(title="HNA population")+
guides(color = FALSE)
p_LNA <- ggplot(counts, aes(x = ExactTime, y = LNA.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom")+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
labs(title="LNA population")+
guides(color = FALSE)
grid_arrange_shared_legend(p_counts, p_HNA, p_LNA, ncol = 3)

Diversity dynamics
# Resample to atleast 10,000 cells for diversity assay
# flowData_transformed_subs <- FCS_resample(flowData_transformed, sample = 10000, replace = TRUE)
# Calculate phenotypic alpha diversity
diversity_fcm <- Diversity_rf(flowData_transformed, param = param, cleanFCS = FALSE, parallel = TRUE,
ncores = 10)
## -------------------------------------------------------------------------------------------------
## Tue Jan 2 12:10:20 2018 --- Normalizing your FCS data based on maximum FL1-H value
## --- Maximum FL1-H before normalizing: 14.95
## --- Maximum FL3-H before normalizing: 13.27
## --- Maximum SSC-H before normalizing: 17.33
## --- Maximum FSC-H before normalizing: 16.96
## -------------------------------------------------------------------------------------------------
## --- Maximum FL1-H after normalizing: 1
## --- Maximum FL3-H after normalizing: 0.89
## --- Maximum SSC-H after normalizing: 1.16
## --- Maximum FSC-H after normalizing: 1.13
## -------------------------------------------------------------------------------------------------
##
## Tue Jan 2 12:10:58 2018 --- Using 10 cores for calculations
## Tue Jan 2 12:36:18 2018 --- Closing workers
## Tue Jan 2 12:36:18 2018 --- Alpha diversity metrics (D0,D1,D2) have been computed after 100 bootstraps
## -----------------------------------------------------------------------------------------------------
##
# Add metadata to phenotypic diversity estimate
diversity_fcm <- dplyr::left_join(diversity_fcm, counts, by = c("Sample_names" = "Samples"))
diversity_fcm <- diversity_fcm %>% dplyr::filter(Timepoint > 5) # Only consider after first 5 samples due to bleaching of tubing
# Plot results
p_div <- ggplot(diversity_fcm, aes(x = ExactTime, y = D2, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer("Nutrient condition", palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom",
strip.text = element_text(size = 16))+
ylab(expression("Phenotypic diversity - D"[2]))+
facet_grid(~NutrientCondition)+
xlab("Time (h)")+
guides(fill = FALSE, color = FALSE)+
geom_ribbon(aes(ymin = D2 - sd.D2, ymax = D2 + sd.D2), alpha = 0.3)
print(p_div)

# Reshape combined data
diversity_fcm_long <- tidyr::gather(diversity_fcm, population, Density, Total.cells, LNA.cells, HNA.cells, D2)
diversity_fcm_long$population <- plyr::revalue(diversity_fcm_long$population, c("Total.cells"="Whole population", "HNA.cells"="HNA population", "LNA.cells"="LNA population", "D2" = "Phenotypic diversity"))
# Combine diversity and count plot
p_count2 <- ggplot(counts, aes(x = ExactTime, y = Total.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom",
strip.text = element_text(size = 16))+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
facet_grid(~NutrientCondition)+
guides(color = FALSE, fill = FALSE)
p_HNA2 <- ggplot(counts, aes(x = ExactTime, y = HNA.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom",
strip.text = element_text(size = 16))+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
facet_grid(~NutrientCondition)+
guides(color = FALSE, fill = FALSE)
p_LNA2 <- ggplot(counts, aes(x = ExactTime, y = LNA.cells, fill = NutrientCondition))+
geom_line(aes(color = NutrientCondition))+
geom_point(shape = 21, size = 4)+
theme_bw()+
scale_fill_brewer("Nutrient condition", palette = "Accent")+
scale_color_brewer(palette = "Accent")+
theme(axis.text=element_text(size=16), axis.title=element_text(size=20),
title=element_text(size=20), legend.text=element_text(size=16),
legend.direction = "horizontal",legend.position = "bottom",
strip.text = element_text(size = 16))+
ylab("Cell density (cells/µL)")+
xlab("Time (h)")+
facet_grid(~NutrientCondition)+
guides(color = FALSE, fill = FALSE)
grid.arrange(p_count2, p_div, nrow = 2)

grid.arrange(p_HNA2, p_div, nrow = 2)

grid.arrange(p_LNA2, p_div, nrow = 2)
